'''
Created on 2019年6月19日

@author: guihe
'''
import datetime
import traceback


'''
@author: guihe
@param variate: variate
@return: variate is the standard type?
'''
def typeof_by_str(variate):
    type=None
    if variate == None:
        return 'NoneType'
    if isinstance(variate,int):
        type = "int"
    elif isinstance(variate,str):
        type = "str"
    elif isinstance(variate,float):
        type = "float"
    elif isinstance(variate,list):
         type = "list"
    elif isinstance(variate,tuple):
        type = "tuple"
    elif isinstance(variate,dict):
        type = "dict"
    elif isinstance(variate,set):
        type = "set"
    return type

def log_content_creater(t, msg=''):
    content_ = ''
    try:
        for i in t.__dict__:
        #     print(typeof_by_str(t.__dict__[i]))
            if typeof_by_str(t.__dict__[i]) == None:
                content_ = content_ +' | '+ str(i)+':'+str(t.__dict__[i].__dict__)
            else:
                content_ = content_ +' | '+ str(i)+':'+str(t.__dict__[i])
    except:
        content_ = msg + ':' +str(t)
    return content_

'''
@author: guihe
@该类用于将用将[str,str,str]的字符串 分割成str 的lst
@param:str_content
@return: [str,....]
'''
def str_2_lst(str_content):
    if typeof_by_str(str_content) != 'str':
        return []
    test_str_t = str_content.strip().replace('[', '')
    test_str_t = test_str_t.strip().replace(']', '') 
    
    if len(test_str_t) >0:
        return test_str_t.split(',')
    
    return []

'''
@author:guihehans
@该类用于提取[000001,F,90;000002,F,10]
@param:str_content
@return: [[000001,F,90],[000002,F,10]
'''


def strlst_2_lst(str_content):
    if typeof_by_str(str_content) != 'str':
        return []
    # 去除开头末尾[]
    test_str_t = str_content.strip().replace('[', '')
    test_str_t = test_str_t.strip().replace(']', '')
    # 以分号分隔子元素
    sub_str = test_str_t.split(';')
    result = []
    # 在子元素内 逗号分隔
    for item in sub_str:
        item = item.split(',')
        result.append(item)

    return result


'''
@author: guihe
@this method is used for printing traceback when the exception occured  
@retrun: traceback info in one line
'''
def traceback_printer():
#     'traceback.format_exc():\n%s' % traceback.format_exc()
    re_str = traceback.format_exc().replace('\n', '|||')
    return  re_str




'''
检验字符串是否是合法日期格式
'''
def isVaildDate(date):
    try:
        if ":" in date:
            datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
        else:
            datetime.datetime.strptime(date, "%Y-%m-%d")
        return True
    except:
        return False

# if __name__ == "__main__":
#     #lock_and_invoke_update()
#     print('test')
#     df=read_csv(const.SYS_WORK_DAY)
#     print(df.head(1))
